package ph.gov.marikina.mcsmtms.domain;

import java.io.Serializable;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import org.codehaus.jackson.annotate.JsonBackReference;

import ph.gov.marikina.mcsmtms.constants.GlobalConstants.Roads;
import ph.gov.marikina.mcsmtms.constants.GlobalConstants.SituationTypes;
import ph.gov.marikina.mcsmtms.constants.GlobalConstants.TrafficConditionTypes;
import ph.gov.marikina.mcsmtms.utils.Utils;

@Entity
@Table(name="mobile_user_report")
public class MobileUserReport implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = -7484006402604456127L;

	@Id
	@GeneratedValue
	@Column(name="id")
	private Integer id;
	//private String situationReportId;

	@Column(name="reporter", nullable=false, insertable = false, updatable = false)
	private Integer reporter;
	
	@ManyToOne(fetch = FetchType.EAGER)
	@JoinColumn(name = "reporter")
	private User user;
	
	@Column(name="date_time", nullable=false)
	private Date reportDateTime;
	
	@Column(name="road", nullable=false)
	private String road;
		
	@Column(name="situation", nullable=false)
	private String situation;
	
	@Column(name="traffic_condition", nullable=false)
	private String trafficCondition;
	
	@Column(name="description")
	private String description;
	
	@Column(name="location_lat", nullable=false)
	private Double locationLat;
	
	@Column(name="location_lng", nullable=false)
	private Double locationLng;
	
	@Column(name="speed", nullable=false)
	private Double speed;

	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	public String getRoad() {
		return road;
	}
	
	public String getRoadDesc() {
		if(null == road || road.isEmpty()) return "";
		return Roads.getDescriptionByCode(road);
	}
	
	public void setRoad(String road) {
		this.road = road;
	}

	public Integer getReporter() {
		return reporter;
	}

	public void setReporter(Integer reporter) {
		this.reporter = reporter;
	}

	public Date getReportDateTimeValue() {
		return reportDateTime;
	}
	//return Utils.formatDefaultDate(lastUpdateDateTime);
	
	public String getReportDateTimeString() {
		return Utils.formatDefaultDate(reportDateTime);
	}

	public void setReportDateTime(Date reportDateTime) {
		this.reportDateTime = reportDateTime;
	}

	public String getSituation() {
		return situation;
	}
	
	public String getSituationDesc() {
		if(null == situation || situation.isEmpty()) return "";
		return SituationTypes.getDescriptionByCode(situation);
	}
	
	public void setSituation(String situation) {
		this.situation = situation;
	}

	public String getTrafficCondition() {
		return trafficCondition;
	}
	
	public String getTrafficConditionDesc() {
		if(null == trafficCondition || trafficCondition.isEmpty()) return "";
		return TrafficConditionTypes.getDescriptionByCode(trafficCondition);
	}

	public void setTrafficCondition(String trafficCondition) {
		this.trafficCondition = trafficCondition;
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public Double getLocationLat() {
		return locationLat;
	}

	public void setLocationLat(Double locationLat) {
		this.locationLat = locationLat;
	}

	public Double getLocationLng() {
		return locationLng;
	}

	public void setLocationLng(Double locationLng) {
		this.locationLng = locationLng;
	}

	public Double getSpeed() {
		return speed;
	}

	public void setSpeed(Double speed) {
		this.speed = speed;
	}

	public User getUser() {
		return user;
	}

	public void setUser(User user) {
		this.user = user;
	}
	
	public String getDetails() {
		String details = "";
		
		details += "Reporter: " + getReporter() + "\n";
		details += "DateTime: " + getReportDateTimeString() + "\n";
		details += "Road: " + getRoad() + "\n";
		details += "Situation: " + getSituation() + "\n";
		details += "TrafficCondition: " + getTrafficCondition() + "\n";
		details += "Speed: " + getSpeed() + "\n";
		details += "Description: " + getDescription() + "\n";
		
		return details;
	}
}

